﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Pulse
{
    class Camera
    {
        protected float camZoom;
        public Matrix camTransform;
        public Vector3 camPosition;
        protected float camRotation;

        public Camera()
        {
            camZoom = 1.0f;
            camRotation = 0.0f;
            camPosition = Vector3.Zero;
        }

        public float Zoom
        {
            get { return camZoom; }
            set { camZoom = MathHelper.Clamp(value, 0.1f, 2.0f); }
        }

        public void Move(Vector2 position)
        {
            camPosition += new Vector3(position, 0);
        }

        public Vector3 Position
        {
            get { return camPosition; }
            set { camPosition = value; }
        }


        public Matrix getTransformation(GraphicsDeviceManager graphic)
        {
            camTransform = Matrix.CreateTranslation(
                new Vector3(-camPosition.X, -camPosition.Y, -camPosition.Z)) *
                Matrix.CreateScale(new Vector3(camZoom, camZoom, camZoom)) *
                Matrix.CreateTranslation(new Vector3(graphic.GraphicsDevice.Viewport.Width * 0.5f,
                                                     graphic.GraphicsDevice.Viewport.Height * 0.5f, 0));

            return camTransform;
        }

        public void Update(Vector3 point, GameTime gametime, KeyboardState ks)
        {
            Position = point;
        }
    }
}
